package edu.psu.geovista.app.plot.axis;

import edu.psu.geovista.classification.Category;

import java.awt.*;
import java.util.ArrayList;

/*
 * GeoVISTA Center (Penn State, Dept. of Geography)
 * Copyright (c), 2003-2011,  Jin Chen and Alan M. MacEachren, GeoVISTA Center, Penn State University
 * All Rights Researved.
 *
 * This library is developed and distributed for free usage,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * You can redistribute and/or modify it under the terms of the
 * Simplified BSD License
 *
 *
 *
 *
 *
 *
 *
 * Description
 *
 * Date: May 31, 2003
 * Time: 9:34:37 PM
 * @author Jin Chen
 */

public class ColorBar {

    private Point location;//origi
    private Dimension size;
    //private Color[] colors;
    private ArrayList ctgList;
    private boolean vertical;

    public ColorBar(Point oLoc, Dimension size,ArrayList ctgList, boolean vertical) {
        location = oLoc;
        this.size = size;
        this.ctgList =ctgList;
        this.vertical=vertical;

    }

    public void paintComponent(Graphics g){
        if(ctgList==null)return;
        int w=size.width ;
        int h=size.height ;
        Graphics2D g2d=(Graphics2D)g;
        Color old=g2d.getColor() ;
        if (vertical){
            //int step=(int)Math.round(h /colors.length) ;
            int sx=(location.x -w);
            int sy=location.y;
            for (int i=0;i<ctgList.size() ;i++){
                Category ctg=(Category) ctgList.get(i);
                int min=(int)ctg.getMin() ;
                Color color=ctg.getColor() ;

                g2d.setColor(color);
                if(i!=(ctgList.size()-1)){
                    g2d.fillRect(sx,sy,w,min-sy);
                    sy=0+min;
                }
                else{
                    g2d.fillRect(sx,sy,w,(h+location.y-sy));
                }
            }
        }

        g2d.setColor(old);


    }


    public void setCtgList(ArrayList ctgList) {
        this.ctgList = ctgList;
    }

    public void setPosition(Point position) {
        this.location = position;
    }
}
